<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>快照对比页面,情绪计算</title>
<style type="text/css">
table.gridtable {
	font-family: verdana, arial, sans-serif;
	font-size: 11px;
	color: #333333;
	border-width: 1px;
	border-color: #666666;
	border-collapse: collapse;
}

table.gridtable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #dedede;
}

table.gridtable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #666666;
	background-color: #ffffff;
}

tr:hover td {
	background: none;
}

tr:hover {
	background-color: none;
}
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
}
table {
  border-collapse: collapse;
  width: 100%;
}

th, td {
  padding: 8px;
  text-align: left;
}

th {
  background-color: #f2f2f2;
}
#myDiv { 
     top: 0px;
     right: 0;
     background-color: #f1f1f1;
     padding: 10px;
     overflow-y:auto;
   }
</style>
<meta charset="UTF-8">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/grid1.0.js"></script>
</head>
<body style="overflow:auto;">

<button id="bt0">计算所有分歧(当天)</button>
<button id="bt1">计算2.5分歧(当天)</button> 
<button id="bt1_1">计算分歧(过天)</button> 
<button id="bt2">涨跌幅排序</button>
<button id="bt2_1">5天换手总和排序</button>
<input type="text" style="width:50px;" id="sumcj" placeholder="小于" value="10"> 
<button id="bt3">隐藏小于成交总和股票</button>
<button id="bt4">换手差距排序</button>
<input type="texd" style="width:50px;" id="zhang3" placeholder="小于" value="8">
<input type="texd" style="width:50px;" id="zhang4"  placeholder="小于" value="-8">
<button id="bt5">隐藏昨日涨幅不在区间个股</button>
<button id="bt4_1">距离最小价格排序</button>

<select id="mySelect"></select>
<div id="myDiv"></div>
<script type="text/javascript">
(function(){ 
	
 
	function loadUrl(){
		$('table tr').each(function() {
		    var thirdColumn = $(this).find('td:eq(2)');
		    var linkText = thirdColumn.text();  
		    thirdColumn.html('<a href=http://quote.eastmoney.com/concept/'+linkText+'.html target="_blank">' + linkText + '</a>');
		 });
	}
	
	function load(createTime){
		//alert(createTime);
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getFenQidayLTList",  
			dataType:'text',
			data:{createTime:createTime},
			success : function(msg) {  
				 $("#myDiv").html(msg);
				 $("#mytalbe").addClass("gridtable");  
				 chang2wei();
				 $('table td[name="table_id"]').hide();
				 $('table th[name="table_id"]').hide();
				 $('table td[name="price"]').hide();
				 $('table th[name="price"]').hide();
				 
				 $('table td[name="temp1"]').hide();
				 $('table th[name="temp1"]').hide();
				 
				 $('table td[name="temp2"]').hide();
				 $('table th[name="temp2"]').hide();
				 
				 $('table td[name="temp3"]').hide();
				 $('table th[name="temp3"]').hide();
				 loadUrl();
				 
				 $("table td:nth-child(9)").each(function() {
					    var value = parseFloat($(this).text());
					    if (value < 0) {
					        $(this).css("color", "green");
					    } else if (value >= 0) {
					        $(this).css("color", "red");
					    }
				}); 
				 /*
				 $("table td:nth-child(8)").each(function() {
					    var value = parseFloat($(this).text());
					    if (value < 0) {
					        $(this).css("color", "green");
					    } else if (value >= 0) {
					        $(this).css("color", "red");
					    }
				}); */
				 
				 $('table tr').each(function() {
				        var thirdTdValue = $(this).find('td:eq(1)').text();  
						   var allCode = getCookie('allCode');
						   var arr =allCode.split(",");
						   for(var i=0;i<arr.length;i++){ 
							   if(arr[i]==thirdTdValue){
								   $(this).children().css('background-color', 'gray')
								   break;
							   }
						   } 
				  });
				 
				 
				 
				 
			}
		}); 
	}
	
	load('');
	loaoDayCreateTime();  
	
	$(document).on('dblclick', 'tr', function() {
		var allCode = getCookie('allCode');
		if(allCode.length>0){
			var text = $(this).find("td:eq(1)").text();
			
			var temp = allCode.indexOf(text);
			if(temp==-1){
				allCode+=","+text;
				setCookie('allCode', allCode,1000);
			}else{
				allCode = allCode.replace(text,"");
				setCookie('allCode', allCode,1000);
			}
			 
		}else{
			var text = $(this).find("td:eq(3)").text();
			allCode=text;
			setCookie('allCode', allCode,1000);
			return;
		} 
	});
	
	
	
	
	
	function jusuanfenqi(flag){  
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getFenQidayLT",  
			data:{flag:flag},
			dataType:'text',
			success : function(msg) {  
			  alert("调用成功");
			}
		});
	}; 

	function loaoDayCreateTime(flag){  
		$.ajax({
			type : "get",
			url : "${pageContext.request.contextPath}/getFenQidayLTSelectDIS",  
			 
			dataType:'json',
			success : function(msg) {  
			 // alert(msg); 
			 	 $.each(msg, function(index, value) {
				    $('#mySelect').append($('<option>', {
				      value: value,
				      text: value
				    }));
				  });
			 	 
			 	 $('#mySelect').change(function(){
					    var selectedValue = $(this).val(); 
					   // alert(selectedValue);
						load(selectedValue); 
				 });
				
			 	 
			}
		});
	}; 
	 
	
	var bt1t = true;
	
	$("#bt0").click(function(){
		jusuanfenqi(-1);
	});
	$("#bt1").click(function(){
		jusuanfenqi(0);
	});

	$("#bt1_1").click(function(){
		jusuanfenqi(1);
	});
	
	$("#bt2").click(function(){
		
		if(bt1t == true){
			bt1t =false;
		}else{
			bt1t = true;
		}
		
		sortTable(8,bt1t);
	});
	
	$("#bt2_1").click(function(){
		
		if(bt1t == true){
			bt1t =false;
		}else{
			bt1t = true;
		}
		
		sortTable(4,bt1t);
	});
	
	$("#bt3").click(function(){
		 $('table tr').each(function() {
		        var cellValue = parseFloat($(this).find('td[name="zuorihuanshoulv"]').text());

		        // Check if the cell value is greater than 3 or less than -2.5
		        if (cellValue < $("#sumcj").val()) {
		            $(this).hide(); // Hide the current row if the condition is met
		        }
		    });
	}); 
	
	
	$("#bt4").click(function(){
			
			if(bt1t == true){
				bt1t =false;
			}else{
				bt1t = true;
			} 
			sortTable(4,bt1t);
	});
	
	$("#bt4_1").click(function(){
		
		if(bt1t == true){
			bt1t =false;
		}else{
			bt1t = true;
		} 
		sortTable(11,bt1t);
});
	
	
	$("#bt5").click(function(){
		 $('table tr').each(function() {
		        var cellValue = parseFloat($(this).find('td[name="zuorizhangdiefu"]').text());

		        // Check if the cell value is greater than 3 or less than -2.5
		       if (cellValue < $("#sumcj").val()) {
		            $(this).hide(); // Hide the current row if the condition is met
		        }
		    });
	}); 
	
	function sortTable(columnIndex, ascending) {
	    // 选择包含数字的行，并按特定列中包含的数字排序
	    var rows = $('table tbody tr').get();
	    rows.sort(function(rowA, rowB) {
	        var numA = parseFloat($(rowA).find('td').eq(columnIndex).text());
	        var numB = parseFloat($(rowB).find('td').eq(columnIndex).text());

	        if (ascending) {
	            return numA - numB;
	        } else {
	            return numB - numA;
	        }
	    });

	    // 重新排列行
	    $.each(rows, function(index, row) {
	        $('table tbody').append(row);
	    });
	}
	function sortTable(columnIndex, ascending) {
	    // 选择包含数字的行，并按特定列中包含的数字排序
	    var rows = $('table tbody tr').get();
	    rows.sort(function(rowA, rowB) {
	        var numA = parseFloat($(rowA).find('td').eq(columnIndex).text());
	        var numB = parseFloat($(rowB).find('td').eq(columnIndex).text());

	        if (ascending) {
	            return numA - numB;
	        } else {
	            return numB - numA;
	        }
	    }); 
	    // 重新排列行
	    $.each(rows, function(index, row) {
	        $('table tbody').append(row);
	    });
	}
	
	
	
	function loadUrl(){
		$('table td[name=code1]').each(function() {
		    var linkText = $(this).text();  
		    if(linkText=="code"){
		    	return;
		    }
		    $(this).html('<a href="javascript:void(0);">' + linkText + '</a>').click(function(){  
		    	if(linkText.indexOf("6")==0){
		    		window.open('http://quote.eastmoney.com/concept/sh'+linkText+'.html'); 	
		    	}else{
		    		window.open('http://quote.eastmoney.com/concept/sz'+linkText+'.html'); 
		    	}
		    	   
	    		  
		    });;
		 });
	}
	
	function checkURLExists(url, callback) {
	    $.ajax({
	        type: 'HEAD',
	        url: url,
	        success: function() {
	            callback(true);
	        },
	        error: function() {
	            callback(false);
	        }
	    });
	}

	// Usage
	
	
	function chang2wei(){
		
		$('table td[name="zuorizhangdiefu"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		});
		
		$('table td[name="zuorihuanshoulv"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		});
		$('table td[name="dqhuanshoulv"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		});
		$('table td[name="chaju"]').each(function() {
		    var cellValue = $(this).text();
		    
		    // 将单元格中的文本转换为浮点数，并格式化为两位小数
		    var floatValue = parseFloat(cellValue);
		    if (!isNaN(floatValue)) {
		        var formattedValue = floatValue.toFixed(2);
		        $(this).text(formattedValue);
		    }
		}); 
	}
	function setCookie(cookieName, cookieValue, expirationDays) {
	    const date = new Date();
	    date.setTime(date.getTime() + (expirationDays * 24 * 60 * 60 * 1000));
	    const expires = "expires=" + date.toUTCString();
	    document.cookie = cookieName + "=" + cookieValue + ";" + expires + ";path=/";
	}
	function getCookie(cookieName) {
	    const name = cookieName + "=";
	    const decodedCookie = decodeURIComponent(document.cookie);
	    const cookieArray = decodedCookie.split(';');
	    
	    for (let i = 0; i < cookieArray.length; i++) {
	        let cookie = cookieArray[i].trim();
	        if (cookie.indexOf(name) === 0) {
	            return cookie.substring(name.length);
	        }
	    }
	    return "";
	}
	
})();
  
</script>

</body>
</html>